package api

import (
	"github.com/gin-gonic/gin"
	"server/global"
	"server/internal/middleware"
	"server/internal/pkg/response"
	"server/internal/services"
)

// LogApi 管理员日志
var LogApi = new(logApi)

type logApi struct{}

// Router 路由
func (a logApi) Router(r *gin.RouterGroup) {
	api := r.Group("/system_log", middleware.LoginVerification, middleware.PermissionVerification)
	//验证权限
	api.GET("/list", a.list)
	api.GET("/edit", a.detail)
}

// List 列表
func (logApi) list(c *gin.Context) {
	Db := global.GL_DB          //初始化Db
	Db = services.Query(Db, c)  //查询构造
	Db = services.Paging(Db, c) //分页

	//快速搜索
	quickSearch := c.Query("quickSearch")
	if quickSearch != "" {
		Db = Db.Where("title like ?", "%"+quickSearch+"%")
	}

	list, total := services.SystemLog.GetList(Db)

	response.SuccessList(c, list, total)
}

// Detail 单条
func (logApi) detail(c *gin.Context) {
	id := c.Query("id")

	detail := services.SystemLog.GetById(id)

	response.SuccessData(c, detail, "")
}
